package com.wenx.file;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * 读取大文件方式 2G以上
 */
public class BigFileReaderDemo {

    public static void main(String[] args) {
        try {
            String inputFile = "F:\\学习文档\\jvm调优.txt";
            String outputFile = "F:\\学习文档\\jvm调优1.txt";
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(inputFile)));
            BufferedReader in = new BufferedReader(new InputStreamReader(bis, StandardCharsets.UTF_8), 10 * 1024 * 1024);// 10M缓存
            FileWriter fw = new FileWriter(outputFile);
            while (in.ready()) {
                String line = in.readLine();
                System.out.println(line);
                fw.append(line);
            }
            in.close();
            fw.flush();
            fw.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

}
